﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExaminationSys.DataAccess.Entity;
using ExaminationSys.Helper;
using Ext.Net;

namespace ExaminationSys.View.SystemManage
{
    public partial class StudentSearchWindow : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public Store GridStore { get; set; }
        public static Action<PageEntity> SearchFun;

        public void Show(Action<PageEntity> _SearchFun)
        {
            SearchFun = _SearchFun;
            this.StudentInfoSearch.Show();
        }

        protected void SearchStudentInfo(object sender, DirectEventArgs e)
        {
            StringBuilder sqlWhere = new StringBuilder(" Status<>0 ");
            if (!string.IsNullOrWhiteSpace(UserID.Text))
            {
                var userid = UserID.Text.Trim();
                userid = userid.SqlSafe();
                sqlWhere.Append(string.Format(" AND UserID like '%{0}%'", userid));
            }
            if (!string.IsNullOrWhiteSpace(LoginID.Text))
            {
                var loginid = LoginID.Text.Trim();
                loginid = loginid.SqlSafe();
                sqlWhere.Append(string.Format(" AND LoginID like '%{0}%'", loginid));
            }
            if (!string.IsNullOrWhiteSpace(UserName.Text))
            {
                var username = UserName.Text.Trim();
                username = username.SqlSafe();
                sqlWhere.Append(string.Format(" AND UserName like '%{0}%'", username));
            }
            if (!string.IsNullOrWhiteSpace(CollegeName.Text))
            {
                var collegename = CollegeName.Text.Trim();
                collegename = collegename.SqlSafe();
                sqlWhere.Append(string.Format(" AND CollegeName like '%{0}%'", collegename));
            }
            if (!string.IsNullOrWhiteSpace(MajorName.Text))
            {
                var majorname = MajorName.Text.Trim();
                majorname = majorname.SqlSafe();
                sqlWhere.Append(string.Format(" AND MajorName like '%{0}%'", majorname));
            }
            if (!string.IsNullOrWhiteSpace(ClassName.Text))
            {
                var classname = ClassName.Text.Trim();
                classname = classname.SqlSafe();
                sqlWhere.Append(string.Format(" AND ClassName like '%{0}%'", classname));
            }
            if (RadioYes.Checked)
                sqlWhere.Append(" and Lock=1");
            else if (RadioNo.Checked)
            {
                sqlWhere.Append(" and Lock=0");
            }

            PageEntity pageEntity = new PageEntity();
            pageEntity.SqlWhere = sqlWhere.ToString();
            SearchFun.Invoke(pageEntity);
            GridStore.Reload();
            StudentInfoSearch.Hide();
        }
    }
}